home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / func / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  9.2 KB  |  414 lines

  1. /*
  2.  * log.c -- routines for maintaining log entries
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include "common.h"
  7. #include "llist.h"
  8. #include "display.h"
  9. #include "ui.h"
  10. #include "reg.h"
  11. #include "log.h"
  12.  
  13. struct logent *curfunc = NULL;    /* the current log entry (not yet evaled) */
  14. struct logent *lastfunc = NULL;    /* the last 'evaled' log entry */
  15. struct logent *loghead, *logtail;    /* head and tail of log list */
  16.  
  17. static int lid = 1;
  18. struct logent *newfunc(), *log_by_id();
  19.  
  20. XFontStruct *xfs;        /* structure for holding font information.
  21.                  * initialized in init_log() */
  22.  
  23. /****************************************************************/
  24. init_log()
  25. {
  26.     lid = 1;
  27.  
  28.     curfunc = newfunc();
  29.     loghead = logtail = curfunc;
  30.  
  31.     /*
  32.      * get font for log label numbers load an XFonstStruct off the server and
  33.      * make that the current font
  34.      */
  35.  
  36.     if (!(xfs = XLoadQueryFont(display, "8x13bold"))) {
  37.     fprintf(stderr, "Font 8x13bold not found, trying \'fixed\' \n");
  38.     if (!(xfs = XLoadQueryFont(display, "fixed"))) {
  39.         fprintf(stderr, "error geting fonts, exitting...\n");
  40.         exit(-1);
  41.     }
  42.     }
  43.     XSetFont(display, gc, xfs->fid);
  44.  
  45.     return;
  46. }
  47.  
  48. /*************************************************************/
  49. struct logent *
  50. newfunc()
  51. {
  52.     struct logent *f;
  53.  
  54.     f = (struct logent *) malloc(sizeof(struct logent));
  55.     f->opcode = 0;
  56.     f->id = lid;
  57.  
  58. #ifdef DEBUG
  59.     printf("New function: ID# = %d \n", lid);
  60. #endif
  61.  
  62.     f->fnum = -1;        /* will assign appropriate frame number in
  63.                  * log_perm() */
  64.     f->reg = f->pvreg = NULL;
  65.     f->sbs = NULL;
  66.     f->auxdata = NULL;
  67.     f->auxdsize = 0;
  68.     f->trace = NULL;
  69.     f->hist = NULL;
  70.     f->zoom = NULL;
  71.     f->next = f->prev = NULL;
  72.  
  73.     lid++;            /* set next lid # */
  74.  
  75.     return f;
  76. }
  77.  
  78. /***************************************************************/
  79. /* log_del() -- delete function out of log */
  80. log_del(id)
  81.     int       id;
  82. {
  83.     XPoint    pt;
  84.     struct logent *func;
  85.  
  86.     if ((func = log_by_id(id)) == NULL)
  87.     return;
  88.  
  89.     printf("deleting object # %d from log\n", func->id);
  90. #ifdef DEBUG
  91.     printf("before delete:\n");
  92.     show_log_list();        /* for debugging */
  93. #endif
  94.  
  95.     refresh_reg(func->reg);
  96.     free_reg(func->reg);
  97.     free_reg(func->pvreg);
  98.     if (func->sbs != NULL) {
  99.     pt.x = itod(func->sbs->x);
  100.     pt.y = itod(func->sbs->y);
  101.     /* redraw image under log # */
  102.     XPutImage(display, img_win->d_xid, gc, disp_ximg,
  103.           pt.x, pt.y - 13, pt.x, pt.y - 13,
  104.           func->sbs->metr.width,
  105.           func->sbs->metr.ascent + func->sbs->metr.descent + 4);
  106.     free(func->sbs);
  107.     func->sbs = NULL;
  108.     }
  109.     llist_del((llist *) func, (llist **) & loghead, (llist **) & logtail);
  110.  
  111.     curfunc = logtail;
  112.     curfunc->id--;
  113.     lid--;
  114.  
  115. #ifdef DEBUG
  116.     printf("after delete:\n");
  117.     show_log_list();        /* for debugging */
  118. #endif
  119. }
  120.  
  121. /*********************************************************************/
  122. renumber_logged_objects()
  123. {
  124.     struct logent *func;
  125.     char      title[80];
  126.     int       id = 1;
  127.  
  128.     func = loghead;
  129.     while (func != NULL) {
  130.     func->id = id;
  131.     log_label(func);
  132.     switch (func->opcode) {
  133.     case LINE_TRACE:
  134.         if (func->trace != NULL) {
  135.         sprintf(title, "Trace: %d", func->id);
  136.         xv_set(func->trace->win_info->trwin, XV_LABEL, title, NULL);
  137.         }
  138.         break;
  139.     case HISTOGRAM:
  140.         if (func->hist != NULL) {
  141.         sprintf(title, "Histogram: %d", func->id);
  142.         xv_set(func->hist->histo_display->display, XV_LABEL, title, NULL);
  143.         }
  144.         break;
  145.     case ZOOM:
  146.         if (func->zoom != NULL) {
  147.         sprintf(title, "Zoom: %d", func->id);
  148.         xv_set(func->zoom->display->zmwin, XV_LABEL, title, NULL);
  149.         }
  150.         break;
  151.     case DISTANCE:
  152.         break;
  153.     case ANGLE_MES:
  154.         break;
  155.     case ANNOTATE:
  156.         break;
  157.     case COMMENT:
  158.         break;
  159.  
  160.     }
  161.     id++;
  162.     func = func->next;
  163.     }
  164.  
  165.  
  166. }
  167.  
  168. /*********************************************************************/
  169. show_log_list()
  170. {                /* for debugging */
  171.     struct logent *func;
  172.  
  173.     if (loghead == NULL)
  174.     return;
  175.  
  176.     printf("head: id= %d; ", loghead->id);
  177.     func = loghead->next;
  178.     while (func != NULL) {
  179.     printf("next: id= %d; ", func->id);
  180.     func = func->next;
  181.     }
  182.  
  183.     printf("tail: id= %d; ", logtail->id);
  184.     printf("curfunc: id= %d \n", curfunc->id);
  185. }
  186.  
  187. /*********************************************************************/
  188. /* clear_log() -- clears entire log */
  189. clear_log()
  190. {
  191.     struct logent *func;
  192.  
  193. #ifdef DEBUG
  194.     printf("clear_log\n");
  195. #endif
  196.  
  197.     func = logtail->prev;    /* clear logged objects, starting from the
  198.                  * end if the list */
  199.     while (func != NULL && func->id > 0) {
  200.     fxn_clear(func);
  201.     log_del(func->id);
  202.     func = logtail->prev;    /* new logtail now ! */
  203.     }
  204. }
  205.  
  206. /**********************************************************************/
  207. /* log_by_id() -- get a log entry by its id # */
  208. struct logent
  209.          *
  210. log_by_id(id)
  211.     int       id;
  212. {
  213.     struct logent *trav;
  214.  
  215.     for (trav = loghead; trav != NULL; trav = trav->next) {
  216.     if (trav->id == id)
  217.         return trav;
  218.     }
  219.     return NULL;
  220. }
  221.  
  222. /**********************************************************************/
  223. /* log_perm -- move curfunc into the log and initialize another one
  224.  *             this is called everytime 'eval' is hit
  225.  */
  226. log_perm()
  227. {
  228.     struct logent *next;
  229.  
  230. #ifdef TRACE_EX
  231.     fprintf(stderr, " in log_perm \n");
  232. #endif
  233.  
  234.     if (curfunc->fnum < 0)
  235.     curfunc->fnum = curframe();
  236.  
  237.     log_label(curfunc);
  238.     orig_img->file_saved = 0;    /* logged object will need save */
  239.  
  240.     next = newfunc();
  241.     next->opcode = curfunc->opcode;    /* copy opcode from previous entry */
  242.  
  243.     /* add new log structure to the end of the list */
  244.     llist_add((llist *) next, (llist **) & loghead, (llist **) & logtail);
  245.  
  246.     curfunc = next;
  247. }
  248.  
  249. /**********************************************************************/
  250. /* check_frame() checks a log id and verifies whether it is in the current
  251.    frame.
  252.  */
  253. int
  254. check_frame(id)
  255.     int       id;
  256. {
  257.     struct logent *ent;
  258.  
  259.     ent = log_by_id(id);
  260.     if (ent == NULL)
  261.     return 0;
  262.     if (ent->fnum == curframe())
  263.     return 1;
  264.     else
  265.     return 0;
  266. }
  267.  
  268. /*****************************************************************/
  269. /* draw_log() -- refresh all points and crosses in all logged objects */
  270. draw_log()
  271. {
  272.     struct logent *trav;
  273.  
  274. #ifdef TRACE_EX
  275.     fprintf(stderr, "in draw_log \n");
  276. #endif
  277.  
  278.     for (trav = loghead; trav != NULL; trav = trav->next) {
  279.     if (trav->fnum == curframe()) {
  280.         if (trav->reg != NULL) {
  281.         draw_reg(trav->reg);
  282.         }
  283.         log_label(trav);
  284.     }
  285.     }
  286.     draw_cpl();
  287. }
  288.  
  289. /**********************************************************************/
  290. /* log_chreg() -- change the region associated with a particular log
  291.    entry. */
  292.  
  293. log_chreg(id, newreg)
  294.     int       id;        /* id of log entry */
  295.     struct region *newreg;    /* new region */
  296. {
  297.     struct logent *ent;
  298.  
  299.     ent = log_by_id(id);
  300.     refresh_reg(ent->reg);
  301.     free_reg(ent->reg);
  302.     ent->reg = newreg;
  303.     /*
  304.      * the new region may have moved sufficiently to justify adding/changing
  305.      * the sbs label
  306.      */
  307.     log_label(ent);
  308.     draw_log();
  309. };
  310.  
  311. /**********************************************************************/
  312. /* add an sbs label to a log */
  313. log_label(ent)
  314.     struct logent *ent;
  315. {
  316.     unsigned  blank;
  317.     XPoint    pt;
  318.     char      msg[12];
  319.  
  320. #ifdef TRACE_EX
  321.     fprintf(stderr, " in log label \n");
  322. #endif
  323.  
  324.     if (ent->fnum != curframe())
  325.     return;
  326.  
  327.     sprintf(msg, "%d", ent->id);
  328.     xv_set(base_win->log_num, PANEL_LABEL_STRING, msg, NULL);
  329.  
  330.     if (ent->sbs != NULL) {
  331.     pt.x = itod(ent->sbs->x);
  332.     pt.y = itod(ent->sbs->y) - 13;
  333.     XPutImage(display, img_win->d_xid, gc, disp_ximg, pt.x,
  334.           pt.y, pt.x, pt.y, ent->sbs->metr.width, 15);
  335.     free(ent->sbs);
  336.     ent->sbs = NULL;
  337.     }
  338.     /* in clean_mode, dont number anotation objects */
  339.     if (clean_mode && ent->opcode == ANNOTATE)
  340.     return;
  341.  
  342.     if (ent->reg == NULL || ent->reg->r_plist == NULL)
  343.     return;
  344.     ent->sbs = (struct strbs *) malloc(sizeof(struct strbs));
  345.     ent->sbs->string = (char *) malloc(10);
  346.     ent->sbs->x = ent->reg->r_plist->cb.left.x;
  347.     ent->sbs->y = ent->reg->r_plist->cb.top.y + 13;
  348.     pt.x = itod(ent->sbs->x);
  349.     pt.y = itod(ent->sbs->y);
  350.     itoa(ent->id, ent->sbs->string);
  351.     XTextExtents(xfs, ent->sbs->string, strlen(ent->sbs->string),
  352.          &blank, &blank, &blank, &ent->sbs->metr);
  353.     /* write the character and get the backing store */
  354.     XSetForeground(display, gc, standout);
  355.     XDrawString(display, img_win->d_xid, gc, pt.x, pt.y,
  356.         ent->sbs->string, strlen(ent->sbs->string));
  357. }
  358.  
  359. /****************************************************************/
  360. /*
  361.    routine to add the log to a header for save operations
  362. */
  363.  
  364. save_log(head)
  365.     struct header *head;
  366. {
  367.     if (loghead != NULL) {
  368.     add_log(head, loghead);
  369.     }
  370. }
  371.  
  372. /**********************************************************************/
  373. /* a couple quick routiens for converting small integers to strings.
  374.  * These are stolen outright from K & R, p. 59-60
  375.  */
  376.  
  377. reverse(s)            /* reverse string s in place */
  378.     char     *s;
  379. {
  380.     int       c, i, j;
  381.  
  382.     for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
  383.     c = s[i];
  384.     s[i] = s[j];
  385.     s[j] = c;
  386.     }
  387. }
  388.  
  389. /********************************************/
  390. itoa(n, s)            /* convert n to characters in s */
  391.     int       n;
  392.     char     *s;
  393. {
  394.     int       i, sign;
  395.  
  396.     if ((sign = n) < 0)
  397.     n = -n;
  398.     i = 0;
  399.     do {
  400.     s[i++] = n % 10 + '0';
  401.     } while ((n /= 10) > 0);
  402.     if (sign < 0)
  403.     s[i++] = '-';
  404.     s[i] = '\0';
  405.     reverse(s);
  406. }
  407.  
  408. /*******************************************/
  409. int
  410. get_current_lid()
  411. {
  412.     return (lid - 1);
  413. }
  414.